<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns:display="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>med-in</title>
    <link rel="stylesheet" href="/admin/layui-v2.4.5/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="/admin/css/admin.css"  media="all">
    <style>
        .layui-fluid {
            padding: 1px;
        }
    </style>
</head>
<body>
<script src="/admin/layui-v2.4.5/layui/layui.js" charset="utf-8"></script>
<div class="layui-fluid">
    <div class="layui-card">
        <!--<div class="layui-card-header">简洁风格</div>-->
        <div class="layui-card-body">
            <div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">订单详情</li>
                    <li>药品详情</li>
                    <li>入库详情</li>
                    <li>报废药品</li>
                    <li>合作供应商</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-card">

                            <div class="layui-card-body"align="left">
                                <table class="layui-hide" id="test-table-1" lay-filter="test-table-1"></table>

                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-row layui-col-space15">
                        <bdiv class="layui-form-item">
                            <div class="layui-inline">
                            <button name="file" type="button2" class="layui-btn" id="test-upload-type2"><i class="layui-icon"></i>EXCEL导入</button>
                            </div>
                        </bdiv>
                        <div class="layui-col-md12">

                            <div class="layui-card">

                                <div class="layui-card-body"align="left">
                                    <table class="layui-hide" id="test-table-totalRow2" lay-filter="test-table-totalRow2"></table>

                                    <script type="text/html" id="test-table-totalRow-toolbarDemo2">
                                        <div class="layui-btn-container">
                                            <!--<button id="delcoin2"class="layui-btn layuiadmin-btn-admin" data-type="batchdel">删除</button>-->
                                            <!--<button id="addcoin" class="layui-btn layuiadmin-btn-admin" data-type="addcoin">添加</button>-->
                                        </div>
                                    </script>

                                </div>
                            </div>
                        </div>
                    </div>
                    </div>

                    <div class="layui-tab-item">
                        <div class="layui-row layui-col-space15">
                        <bdiv class="layui-form-item">

                            <div class="layui-inline">
                                <label class="layui-form-label">药品名称</label>
                                <div class="layui-input-block">
                                    <input id="med_search_name" type="text" name="med_search_name" placeholder="请输入" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button id="button-name" class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search2">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                            <!--<div class="layui-inline">-->
                                <!--<button name="file" type="button" class="layui-btn" id="test-upload-type1"><i class="layui-icon"></i>EXCEL导入</button>-->
                            <!--</div>-->
                        </bdiv>
                        <div class="layui-col-md12">

                            <div class="layui-card">

                                <div class="layui-card-body"align="left">
                                    <table class="layui-hide" id="test-table-totalRow" lay-filter="test-table-totalRow"></table>

                                    <!--<script type="text/html" id="test-table-totalRow-toolbarDemo">-->
                                        <!--<div class="layui-btn-container">-->
                                            <!--<button id="delcoin"class="layui-btn layuiadmin-btn-admin" data-type="batchdel">删除</button>-->
                                            <!--&lt;!&ndash;<button id="addcoin" class="layui-btn layuiadmin-btn-admin" data-type="addcoin">添加</button>&ndash;&gt;-->
                                        <!--</div>-->
                                    <!--</script>-->

                                </div>
                            </div>
                        </div>
                    </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-card">

                        <div class="layui-card-body"align="left">
                            <table class="layui-hide" id="test-table-4" lay-filter="test-table-4"></table>

                            <script type="text/html" id="test-table-totalRow-4">
                            </script>

                        </div>
                    </div></div>
                    <div class="layui-tab-item">
                        <div class="layui-card">

                        <div class="layui-card-body"align="left">
                            <table class="layui-hide" id="test-table-sup" lay-filter="test-table-sup"></table>

                            <script type="text/html" id="test-table-totalRow-sup">
                                <div class="layui-btn-container">
                                    <!--<button id="delcoinsup"class="layui-btn layuiadmin-btn-admin" data-type="batchdelsup">删除</button>-->
                                    <button id="addcoinsup" class="layui-btn layuiadmin-btn-admin" data-type="addcoinsup">添加</button>
                                </div>
                            </script>

                        </div>
                    </div>
                    </div>
                </div>
                </div>
            </div>
        </div>
    </div>

</div>

<!--弹出层-->
<div class="layui-row" id="test" style="display: none;">
    <div class="layui-col-md10">
        <form class="layui-form" id="addPurchaseForm"lay-filter="formPurchase">
            <div class="layui-form-item">
                <label class="layui-form-label">供应商名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="supName" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">联系方式：</label>
                <div class="layui-input-block">
                    <input type="text" name="contract" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注：</label>
                <div class="layui-input-block">
                    <textarea name="remark" placeholder="" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="component-form-element">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    layui.use(['table','element'], function(){
        var $ = layui.$
            ,table = layui.table
            ,form = layui.form
            ,element = layui.element
            ,router = layui.router();

        element.render();

        // element.on('tab(component-tabs-brief)', function(obj){
        //     layer.msg(obj.index + '：' + this.innerHTML);
        // });


        table.render({
            elem: '#test-table-1'
            ,url:'/hospital/sale/dingdan'
            ,cols: [[
                {field:'time', title:'订单日期', width:180, fixed: 'left', unresize: true, sort: true}
                ,{field:'mdc_name', title:'药品名称', width:180}
                ,{field:'count', title:'数量', width:80}
                ,{field:'pat_name', title:'销售对象'}
            ]]

        });

        table.render({
            elem: '#test-table-totalRow2'
            ,url:'/hospital/medicine/page'
            ,toolbar: '#test-table-totalRow-toolbarDemo2'
            ,title: '用户数据表'
            ,limits:10
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'name', title:'药品名称', width:220, fixed: 'left', unresize: true, sort: true,edit: 'text'}
                ,{field:'unit', title:'药品规格', width:100,edit: 'text'}
                ,{field:'company', title:'生产厂家', width:250, sort: true,edit: 'text'}
                ,{field:'jinjia', title:'售价', width:120,sort: true,edit: 'text'}
                ,{field:'inv', title:'库存量', width:80, sort: true}
                ,{field:'limit', title:'报警库存量',edit: 'text'}
            ]]
            ,page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                ,limits:[10,20,30,50,100]
                , jump: function (obj) {
                    console.log(obj)
                }}
        });

        table.render({
            elem: '#test-table-totalRow'
            ,url:'/hospital/page'
            ,toolbar: '#test-table-totalRow-toolbarDemo'
            ,title: '用户数据表'
            ,limits:10
            ,cols: [[
                {field:'name', title:'药品名称', width:180, fixed: 'left', unresize: true, sort: true}
                ,{field:'number', title:'进货单号', width:140}
                ,{field:'count', title:'数量', width:70, sort: true,edit: 'text'}
                ,{field:'date', title:'日期', width:110,sort: true}
                ,{field:'price', title:'进价', width:70, sort: true,edit: 'text'}
                ,{field:'suppiler', title:'供应商',width:120}
                ,{field:'physician', title:'处理人'}
            ]]
            ,page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                ,limits:[10,20,30,50,100]
                , jump: function (obj) {
                    console.log(obj)
                }}
        });
        $(document).on('click','#addcoin',function(){
            var index=layer.open({
                type:1,
                title:"添加药品",
                shadeClose: true,
                area: ['420px', '450px'],
                content:$("#test1").html()
            });
            form.on('submit(component-form-element1)', function(data){
                var obj = eval(data.field);
                $.ajax({
                    url: '/hospital/addMed',
                    dataType: 'json',
                    type: 'post',
                    // async:false,
                    contentType: "application/json; charset=utf-8",
                    data:JSON.stringify({
                        "name":obj.supName,
                        "contract":obj.contract,
                        "remark":obj.remark}),
                    success: function (data) {
                        if (data.code == 0) {
                            parent.layer.msg("添加成功");
                        } else {
                            layer.msg("添加失败");
                        }
                    }
                })
                return false;
            });
        });

        table.render({
            elem: '#test-table-sup'
            ,toolbar: '#test-table-totalRow-sup'
            ,url:'/hospital/allSup'
            ,cols: [[
                {field:'sup_name', title:'供应商名称', width:180, fixed: 'left', unresize: true, sort: true}
                ,{field:'sup_contact_info', title:'联系方式'}
                ,{field:'remark', title:'备注'}
            ]]

        });
            $(document).on('click','#addcoinsup',function(){
                var index=layer.open({
                    type:1,
                    title:"添加供应商",
                    shadeClose: true,
                    area: ['420px', '450px'],
                    content:$("#test").html()
                });
                form.on('submit(component-form-element)', function(data){
                    var obj = eval(data.field);
                    $.ajax({
                        url: '/hospital/addSup',
                        dataType: 'json',
                        type: 'post',
                        // async:false,
                        contentType: "application/json; charset=utf-8",
                        data:JSON.stringify({
                            "name":obj.supName,
                            "contract":obj.contract,
                            "remark":obj.remark}),
                        success: function (data) {
                            if (data.code == 0) {
                                parent.layer.msg("添加成功");
                            } else {
                                layer.msg("添加失败");
                            }
                        }
                    })
                    return false;
                });



            });


        table.render({
            elem: '#test-table-4'
            ,url:'/hospital/sale/broken'
            ,cols: [[
                {field:'name', title:'药品名称', width:180, fixed: 'left', unresize: true, sort: true}
                ,{field:'count', title:'数量', width:80, sort: true}
                ,{field:'time', title:'日期', width:120,sort: true}
                ,{field:'user', title:'处理人', width:80, sort: true}
                ,{field:'remark', title:'备注'}
            ]]
            ,page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                ,limits:[10,20,30,50,100]
                , jump: function (obj) {
                    console.log(obj)
                }}
        });

        table.on('edit(test-table-totalRow2)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
            $.ajax({
                url: "/hospital/medicine/update",
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data:JSON.stringify({"id":data.id,
                    "field":field,"value":value}),
                success: function (e) {
                    if (e.code == 0) {
                        layer.msg("更改成功");
                    } else {
                        layer.msg("更改失败");
                    }
                },
                error: function (e) {
                    layer.msg(e);
                }
            })
        });
        table.on('edit(test-table-totalRow)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
            $.ajax({
                url: "/hospital/updatePurchase",
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data:JSON.stringify({"id":data.id,
                    "field":field,"value":value}),
                success: function (e) {
                    if (e.code == 1) {
                        layer.msg("更改成功");
                    } else {
                        layer.msg("更改失败");
                    }
                },
                error: function (e) {
                    layer.msg(e);
                }
            })
        });
        form.on('submit(LAY-user-back-search2)', function(data){
            var field = data.field;
            var a=$(" #med_search_name ");
            contentType:'application/json;charset=UTF-8';
            type: 'post';
            table.reload('test-table-totalRow', {

                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    'name': a.val()
                }

            });
        });
        $(document).on('click','#delcoin',function(){
            var checkStatus = table.checkStatus('test-table-totalRow')
                , checkData = checkStatus.data; //得到选中的数据

            if (checkData.length === 0) {
                return layer.msg('请选择数据');
            }
            layer.confirm('真的删除吗?', function (index) {

                $.ajax({
                    url: "/hospital/deletePurchase",
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    data:JSON.stringify({
                        "key":checkData}),
                    success: function (e) {
                        if (e.code == 1) {
                            layer.msg("删除成功");
                        } else {
                            layer.msg("删除失败");
                        }
                    },
                    error: function (e) {
                        layer.msg(e);
                    }
                })

                table.reload('test-table-totalRow');
                layer.msg('已删除');
            });
        });

        table.on('edit(test-table-sup)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
            $.ajax({
                url: "/hospital/updateSup",
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data:JSON.stringify({"id":data.id,
                    "field":field,"value":value}),
                success: function (e) {
                    if (e.code == 1) {
                        layer.msg("更改成功");
                    } else {
                        layer.msg("更改失败");
                    }
                },
                error: function (e) {
                    layer.msg(e);
                }
            })
        });

    });
    layui.use('upload', function(){
        var $ = layui.jquery
            , upload = layui.upload;
        upload.render({
            elem: '#test-upload-type2'
            , url: '/excelImportMed.do'
            ,exts: 'xls|xlsx'
            , accept: 'file' //普通文件
            , done: function (res) {
                console.log(res)
                if(res.code == 1){//成功的回调
                    layer.msg("导入成功")
                }else{
                    layer.msg("出错啦");
                }
            }
        });

    });
</script>
</body>
</html>